<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="xb">
        <el-select v-model="queryParams.xb" placeholder="请选择性别" clearable size="small">
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="下拉选择" prop="xlx">
        <el-select v-model="queryParams.xlx" placeholder="请选择下拉选择" clearable size="small">
          <el-option
            v-for="dict in dict.type.sys_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="日期" prop="accTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.accTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['test:testDemo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['test:testDemo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['test:testDemo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['test:testDemo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="testDemoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="xb">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.xb"/>
        </template>
      </el-table-column>
      <el-table-column label="下拉选择" align="center" prop="xlx">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.xlx"/>
        </template>
      </el-table-column>
      <el-table-column label="平铺选" align="center" prop="pbx">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_show_hide" :value="scope.row.pbx ? scope.row.pbx.split(',') : []"/>
        </template>
      </el-table-column>
      <el-table-column label="文件上传" align="center" prop="fileId" />
      <el-table-column label="图片上传" align="center" prop="picId" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.picId" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="日期" align="center" prop="accTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.accTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="memo" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="toDetail(scope.row)"
            v-hasPermi="['test:testDemo:detail']"
            >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['test:testDemo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['test:testDemo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改demo测试对话框 -->
    <el-dialog :title="title" :visible.sync="open" @close='cancel' width="800px" height="50%" append-to-body>
        <Edit @submit="submitForm" @cancel="cancel"  :id="eleId" :open="open" :title="title"/>
    </el-dialog>
      <el-dialog :title="title" :visible.sync="detailOpen" @close='cancel' width="800px" height="50%" append-to-body>
        <Detail @cancel="cancel" :id="eleId" :open="detailOpen" :title="title"/>
    </el-dialog>

  </div>
</template>

<script>
import { listTestDemo, getTestDemo, delTestDemo, addTestDemo, updateTestDemo } from "@/api/test/testDemo";
import Edit from "./edit";
import Detail from "./detail";

export default {
  name: "TestDemo",
  dicts: ['sys_yes_no', 'sys_user_sex', 'sys_show_hide'],
  components: { Edit,Detail },
  data() {
    return {
      eleId: undefined,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // demo测试表格数据
      testDemoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      detailOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        xb: null,
        xlx: null,
        pbx: null,
        fileId: null,
        picId: null,
        accTime: null,
        memo: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询demo测试列表 */
    getList() {
      this.loading = true;
      listTestDemo(this.queryParams).then(response => {
        this.testDemoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.detailOpen=false;
      this.eleId=undefined;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        xb: null,
        xlx: "0",
        pbx: [],
        fileId: null,
        picId: null,
        accTime: null,
        memo: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加demo测试";
    },
    /** 查看详情*/
    toDetail(row) {
      this.reset();
      this.detailOpen = true;
      this.title = "查看 demo测试 详情";
      this.eleId = row.id || this.ids
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.open = true;
      this.eleId = row.id || this.ids
    },
    /** 提交按钮 */
    submitForm() {
        this.open = false;
        this.getList();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除demo测试编号为"' + ids + '"的数据项？').then(function() {
        return delTestDemo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('test/testDemo/export', {
        ...this.queryParams
      }, `testDemo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss" scoped>
</style>
